home *** CD-ROM | disk | FTP | other *** search
- // Gestionnaire de Cycle gadget V0.41
- // (C) 1992 Christophe PASSUELLO
- // Mon Jan 25 21:20:14 1993
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include "mytypes.h"
- #define INTUITION_PREFERENCES_H 0
- #include <intuition/intuition.h>
- #include "IObject_priv.h"
-
-
- IMPORT UBYTE DarkPen, LightPen, Pen1;
-
-
- struct Cycle
- {
- struct ObjectTMV *TMV;
- UWORD ObjectID;
- UWORD Flags;
- STRPTR LabelText;
- struct TextFont *Font;
- struct Window *window;
- struct Requester *requester;
- UWORD ClassFlags;
- struct Box BorderBox;
- struct Gadget Gadget;
- STRPTR *TextArray;
- UWORD ActiveText;
- struct Box TextBox;
- };
-
- // procedures privees
- PRIVATE VOID DisplayInner(struct Cycle *);
-
- // prototypes pour les methodes
- PRIVATE BOOL CycleMsg(struct Cycle *, struct IntuiMessage *);
- VOID ModifyCycle(struct Cycle *, STRPTR *, ULONG);
- PRIVATE VOID DisplayCycle(struct Cycle *);
- PRIVATE VOID EraseCycle(struct Cycle *);
- PRIVATE UWORD CycleValue(struct Cycle *);
- PRIVATE VOID OnCycle(struct Cycle *);
- PRIVATE VOID ActivateCycle(struct Cycle *);
-
-
- // Methodes pour les Cycles
- const static struct ObjectTMV CycleMethod=
- {
- CLASS_CYCLE, sizeof(struct Cycle),
- DisposeObject, CycleMsg, AddObject, RemoveObject, DisplayCycle, EraseCycle,
- ModifyCycle, CycleValue, OffObjectGad, OnCycle, ActivateCycle
- };
-
-
- IMPORT struct Image CycleImage;
-
- #define IMAGEWIDTH 18
-
- //
- // Alloue et Initialise le Cycle
- //
- struct Cycle *CreateCycle(struct NewCycle *nc, UWORD ID)
- {
- struct Cycle *cy;
-
- if (cy = (struct Cycle *) AllocMem(sizeof(struct Cycle), MEMF_PUBLIC|MEMF_CLEAR))
- {
- // Initialise la TMV
- cy->TMV = &CycleMethod;
- cy->ObjectID = ID;
-
- // recupere les champs de NewCycle
- InitObjectGad( (struct ObjectGad *) cy, (struct NewObject *) nc);
- cy->TextArray = nc->TextArray;
-
- // Ajuste les boites
- COPY_BOX(&cy->TextBox, &cy->Gadget.LeftEdge);
- AdjustBox(&cy->TextBox, TRUE);
-
- // initialise le gadget
- cy->Gadget.Flags = GADGHCOMP;
- cy->Gadget.Activation = RELVERIFY;
- cy->Gadget.GadgetType = BOOLGADGET;
-
- // correction pour la TextBox
- cy->TextBox.x += (IMAGEWIDTH-2);
- cy->TextBox.w -= (IMAGEWIDTH-2);
- }
- return (cy);
- }
-
-
- //
- // Renvoie l'index du texte actif
- //
- PRIVATE UWORD CycleValue(struct Cycle *cy)
- {
- return (cy->ActiveText);
- }
-
-
- //
- // Simule l'activation d'un cycle
- //
- PRIVATE VOID ActivateCycle(struct Cycle *cy)
- {
- UWORD index;
-
- // Calcule le texte a afficher
- if (cy->TextArray[cy->ActiveText + 1])
- index = cy->ActiveText + 1;
- else
- index = 0;
-
- // affiche le texte
- ModifyCycle(cy, NULL, index);
- }
-
-
- //
- // Change le texte a afficher
- //
- PRIVATE VOID ModifyCycle(struct Cycle *cy, STRPTR *array, ULONG number)
- {
- struct TextEnv env;
- struct RastPort *rp;
-
- // on modifie le tableau ssi on a fourni un tableau
- if (array)
- cy->TextArray = array;
-
- // initialise l'index
- if (cy->TextArray[number])
- cy->ActiveText = number;
- else
- cy->ActiveText = 0;
-
- if (!(cy->Flags & OBJ_DISABLED))
- {
- rp = cy->window->RPort;
- SaveTextEnv(rp, &env);
-
- // on efface le texte courant
- FastEraseBox(&cy->TextBox, rp);
-
- // affiche le texte
- SetAPen(rp, Pen1);
- SetFont(rp, cy->Font);
- PrintLabelText(rp, &cy->TextBox, cy->TextArray[cy->ActiveText], LABEL_INSIDE);
- RestoreTextEnv(rp, &env);
- }
- }
-
-
- //
- // Gestion de l'IntuiMessage pour le Cycle
- //
- PRIVATE BOOL CycleMsg(struct Cycle *cy, struct IntuiMessage *msg)
- {
- ActivateCycle(cy);
- return (TRUE);
- }
-
-
- //
- // Affiche le Cycle en entier
- //
- PRIVATE VOID DisplayCycle(struct Cycle *cy)
- {
- struct TextEnv env;
- struct RastPort *rp;
-
- // verifie que le Cycle est dans une fenetre
- if (cy->window)
- {
- rp = cy->window->RPort;
- SaveTextEnv(rp, &env);
-
- DisplayInner(cy);
-
- FastDraw3DBox((struct Box *) &cy->BorderBox, rp, BOX_1OUT);
- PrintObjectLabel( (struct Object *) cy, &cy->BorderBox);
- RestoreTextEnv(rp, &env);
-
- if (cy->Flags & OBJ_DISABLED)
- OffObjectGad( (struct ObjectGad *) cy);
- }
- }
-
-
- //
- // Efface le Cycle
- //
- PRIVATE VOID EraseCycle(struct Cycle *cy)
- {
- EraseObjectFrame( (struct Object *) cy, (struct Box *) &cy->BorderBox);
- }
-
-
- //
- // Affiche l'interieur du cycle
- //
- PRIVATE VOID DisplayInner(struct Cycle *cy)
- {
- struct RastPort *rp;
-
- rp = cy->window->RPort;
-
- SetAPen(rp, DarkPen);
- Move(rp, cy->BorderBox.x + 16, cy->BorderBox.y + 2);
- Draw(rp, cy->BorderBox.x + 16, cy->BorderBox.y + cy->BorderBox.h - 3);
-
- SetAPen(rp, LightPen);
- Move(rp, cy->BorderBox.x + 17, cy->BorderBox.y + 2);
- Draw(rp, cy->BorderBox.x + 17, cy->BorderBox.y + cy->BorderBox.h - 3);
-
- DrawImage(rp, &CycleImage, cy->BorderBox.x, cy->BorderBox.y);
- SetAPen(rp, Pen1);
- SetFont(rp, cy->Font);
- PrintLabelText(rp, &cy->TextBox, cy->TextArray[cy->ActiveText], LABEL_INSIDE);
- }
-
-
- //
- // Unghoste un cycle
- //
- PRIVATE VOID OnCycle(struct Cycle *cy)
- {
- struct TextEnv env;
- struct RastPort *rp;
-
- if (cy->Flags & OBJ_DISABLED)
- {
- rp = cy->window->RPort;
-
- OnGadget(&cy->Gadget, cy->window, cy->requester);
- cy->Flags &= (~OBJ_DISABLED);
-
- SaveTextEnv(rp, &env);
- FastEraseBox((struct Box *) &cy->Gadget.LeftEdge, rp);
- DisplayInner(cy);
- RestoreTextEnv(rp, &env);
- }
- }
-